<?php

class Userprojectlinks extends Zend_Db_Table
{
    protected $_name = 'userprojectlinks';
    
    public function checkExist($project_id,$user_id)
    {
        $select = $this->getAdapter();
        $prepare = $select->query('
                SELECT count(*) as all_records 
                FROM userprojectlinks 
                WHERE project_id="'.$project_id.'"
                AND user_id="'.$user_id.'"');
        $result = $prepare->fetchAll(Zend_Db::FETCH_ASSOC);
        return $result[0]['all_records'];
    }
    
    public function ClearLinks($project_id)
    {
        $select = $this->getAdapter();
        $prepare = $select->query('DELETE FROM userprojectlinks 
                                   WHERE project_id="'.(int)$project_id.'"');
    }
    
    public function LinkUser($project_id, $user_id)
    {
        $data = array(
                    'project_id' => $project_id,
                    'user_id' => $user_id);
        $this->insert($data);
    }
}